package pl.edu.agh.inpema.components.receivers.phpBB2Receiver.parser.filters;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.nodes.TagNode;

public class ForumLinkFilter implements NodeFilter {

	public static final String NAME_SUBJECT_LINK = "forumlink";
	public static final String NAME_TOPIC_LINK = "topictitle";
	public static final String NAME_POST_NAME = "name";
	
	private String linkClassName;
	private String tagName;
	
	public ForumLinkFilter(String tagName, String linkClassName) {
		this.tagName = tagName.toLowerCase();
		this.linkClassName = linkClassName; 
	}
	
	public boolean accept(Node node) {
		
		if (node instanceof TagNode) {
			TagNode tag = (TagNode) node;
			if (! this.tagName.equals(tag.getTagName().toLowerCase()))
				return false; 
			if (! this.linkClassName.equals(tag.getAttribute("class"))) {
				return false;
			}
			return true;
		}
		return false;
	}
	
}
